package ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import presenter.BasePresenter;
import ui.activity.BaseActivity;

/**
 * Created by 10153 on 2018/7/31.
 */

public abstract class BaseFragment<P extends BasePresenter> extends Fragment {
    
    protected P mFragPresenter;
    protected BaseActivity mActivity;
    
    private Unbinder unbinder;
    
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mActivity = (BaseActivity)context;
    }
    
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initPresenter();
    }
    
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getFragLayout(), container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }
    
    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
    
    @Override
    public void onDetach() {
        super.onDetach();
        
    }
    
    private void isPresenterExist(String where){
        if(mFragPresenter != null){
            Log.d(this.getClass().getName(), where+": presenter exist!");
        }
    }
    
    protected abstract void initPresenter();
    protected abstract int getFragLayout();
}
